import request from "./request";

/**
 * 加载树形菜单数据
 * @param {* 用户账号} username 
 * @returns 返回树形菜单数据
 */
export const findTreeMenu = async (username) => {
  return await request.get(`/api/menuManagement/find?username=${username}`)
}
/**
 * 查询扁平化菜单数据
 * @param {* 用户账号} username 
 * @returns 返回扁平化菜单数据
 */
export const findMenuList = async (username) => {
  return await request.get(`/api/menu/menusList?username=${username}`)
}

/**
 * 用户登录接口
 * @param {* 用户账号} username 
 * @param {* 用户密码} password 
 * @returns 返回token
 */
export const login = async (username, password) => {
  const params = new URLSearchParams();
  params.append("username", username);
  params.append("password", password);
  return await request.post('/api/user/login', params.toString(), {
    header: { 'content-type': 'application/x-www-form-urlencoded' }
  })
}

/**
 * 注销处理
 * @returns json数据
 */
export const logout = async () => {
  return request.get("/api/user/logout")
}

// 公告模块相关请求接口
/**
 * 查询公告数据
 * @param {* 公告查询参数} params 
 * @returns json格式的公告数据
 */
export const findNotice = async (params) => {
  return await request.get('/api/announcement/find', { params })
}
/**
 * 更新公告
 * @param {* 公告} notice 
 * @returns json格式的公告数据
 */
export const updateNotice = async (notice) => {
  return await request.put('/api/announcement/update', notice, {
    headers: { 'content-type': 'application/json' }
  })
}
/**
 * 新增公告数据
 * @param {* 公告} notice 
 * @returns json格式的数据
 */
export const insertNotice = async (notice) => {
  return await request.post('/api/announcement/insert', notice, {
    headers: { 'content-type': 'application/json' }
  })
}
/**
 * 删除公告数据
 * @param {* 公告主键id数组} noticeIds 
 * @returns json格式的数据
 */
export const deleteNotice = async (noticeIds) => {
  return await request.delete('/api/announcement/delete', {
    headers: { 'content-type': 'application/json' },
    data: noticeIds
  })
}

export const sendMessage = async (jsonData) => {
  const resp = await fetch('https://wxpusher.zjiecode.com/api/send/message', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: jsonData
  })
  return await resp.json()
}

/**
 * 查询树形部门数据
 * @returns 树形部门数据
 */
export const findDeptTree = async () => {
  return await request.get('/api/departmentManagement/find')
}

/**
 * 查询用户和部门数据
 * @param {* 查询参数} params 
 * @returns 用户相关数据
 */
export const findByDept = async (params) => {
  return await request.get('/api/userManagement/find', { params })
}

/**
 * 删除用户的相关信息
 * @param {* 用户的编码id} userIds 
 * @returns json格式的数据
 */
export const deleteUserByDept = async (userIds) => {
  return await request.delete('/api/userManagement/delete', {
    headers: { 'content-type': 'application/json' },
    data: userIds
  })
}

/**
 * 更改用户状态信息
 * @param {* 用户信息} user 
 * @returns json格式的数据
 */
export const updateUserStatus = async (user) => {
  return await request.put('/api/userManagement/updateStatus', user, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 修改用户信息
 * @param {* 收集的用户信息相关数据} user 
 * @returns json格式的数据
 */
export const updateUser = async (user) => {
  return await request.put('/api/userManagement/update', user, {
    headers: { 'content-type': 'application/json' }
  })
}

//修改用户密码
export const updatePassword = async (user) => {
  return await request.put('/api/userManagement/updatePassword', user, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 查询岗位和角色数据
 * @returns json格式的数据
 */
export const findPostRole = async () => {
  return await request.get('/api/userManagement/findPostRole')
}

/**
 * 添加用户信息
 * @param {* 新增用户信息} user 
 * @returns json格式的数据
 */
export const insertUser = async (user) => {
  return await request.post('/api/userManagement/insert', user, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 根据用户ID查询用户信息
 * @param {* 用户ID} userId 
 * @returns json格式的数据
 */
export const findUserById = async (userId) => {
  return await request.get('/api/userManagement/findUserById', { params: { userId } })
}

/**
 * 查询订单数据
 * @param {* 订单查询参数} params 
 * @returns 
 */
export const findSalesOrders = async (params) => {
  return await request.get('/api/salesOrders/find', { params })
}
/**
 * 查询产品信息数据
 * @returns json格式的数据
 */
export const findProduct = async () => {
  return await request.get('/api/materialManagement/findProduct')
}

/**
 * 新增订单数据
 * @param {* 产品信息} product 
 * @returns 
 */
export const saveProduct = async (product) => {
  return await request.post('/api/salesOrders/insert', product, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 删除订单数据
 * @param {* 订单Id} salesOrderIds 
 * @returns 
 */
export const deleteProduct = async (salesOrderIds) => {
  return await request.delete('/api/salesOrders/delete', {
    headers: { 'content-type': 'application/json' },
    data: salesOrderIds
  })
}

/**
 * 查询订单详情数据
 * @param {* 订单Id} salesOrderId 
 * @returns 
 */
export const queryProduct = async (salesOrderId) => {
  return await request.get('/api/salesOrders/query', { params: { salesOrderId } })
}

/**
 * 更新订单数据
 * @param {* 产品信息} product 
 * @returns 
 */
export const updateProduct = async (product) => {
  return await request.put('/api/salesOrders/update', product, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 保存销售出库信息
 * @param {* 销售相关信息} productSales 
 * @returns 
 */
export const saveProductSalse = async (productSales) => {
  return await request.post('/api/salesOutbound/insert', productSales, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 查询销售出库信息
 * @param {* 查询参数} params 
 * @returns 
 */
export const findSalesOutbound = async (params) => {
  return await request.get('/api/salesOutbound/find', { params })
}

/**
 * 批量删除销售出库信息
 * @param {* 主键集合} salseIds 
 * @returns 
 */
export const deleteSalesOutbound = async (salseIds) => {
  return await request.delete('/api/salesOutbound/delete', {
    headers: { 'content-type': 'application/json' },
    data: salseIds
  })
}

/**
 * 根据主键ID查询销售出库信息
 * @param {* 主键ID} salesId 
 * @returns 
 */
export const querySalesOutbound = async (salesId) => {
  return await request.get('/api/salesOutbound/query', { params: { salesId } })
}
/**
 * 更新销售出库信息
 * @param {* 销售出库数据} salesOutbound 
 * @returns 
 */
export const updateSalesOutbound = async (salesOutbound) => {
  return await request.put('/api/salesOutbound/update', salesOutbound, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 添加销售出库行数据
 * @param {* 销售出库行数据} salesLine 
 * @returns 
 */
export const insertSalesOutboundLine = async (salesLine) => {
  return await request.post('/api/salesOutboundLine/insert', salesLine, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 执行销售出库
 * @param {* 出库信息} salesOutbound 
 * @returns 
 */
export const shipments = async (salesOutbound) => {
  return await request.put('/api/salesOutbound/shipments', salesOutbound, {
    headers: { 'content-type': 'application/json' }
  })
}

/**
 * 根据主键删除产品列信息
 * @param {* 产品列主键ID集合} lineIds 
 * @returns 
 */
export const deleteSalesOutboundLine = async (lineIds) => {
  return await request.delete('/api/salesOutboundLine/delete', {
    headers: { 'content-type': 'application/json' },
    data: lineIds
  })
}




